<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Auth extends CI_Controller {
	public function login()
	{	
		$this->load->helper(array('form', 'url'));

        $this->load->library('form_validation');
      
        $this->form_validation->set_rules('username', '用户名', 'required|callback__auth_check');
		$this->form_validation->set_rules('password', '密码', 'required');
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('admin/Login');
        }
        else
        {
            redirect("admin/article/index");
        }
    }
  function _auth_check()
    {	
    	$username=$this->input->post('username');
    	$password=$this->input->post('password');
    	$this->load->model("Auth_model");
    	$data=$this->Auth_model->get_one($username,$password);
        if ($data)
        {	
        	$this->session->set_userdata('is_login', 'true');
            $_SESSION['username']=$username;
        	 return TRUE;     
        }
        else
        {
        	 $this->form_validation->set_message('_auth_check', ' 用户名或者密码错误');
            return FALSE;           
        }
    }
    public function out_login(){
            $this->session->sess_destroy();
            redirect('/admin/auth/login');
        }

}